<?php

namespace App\Services;

use App\Repositories\AbilityRepository;
use BobCoder\Construct\Foundation\Service\Service;

class AbilityService extends Service
{
    protected $repository;

    /**
     * RoleService constructor.
     */
    public function __construct()
    {
        $this->repository = new AbilityRepository();
    }

    /**
     * @param $data
     * @return \App\Models\Role|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
     * @throws \App\Exceptions\BobException
     * @author Bob(bobcoder@qq.com)
     */
    public function saveData($data)
    {
        if (!isset($data['id'])) {
            $rows = $this->repository->firstWhere(['name' => $data['name']]);
            if ($rows) {
                return_bob('权限组已存在');
            }
        }

        return $this->repository->saveData($data);
    }
}
